package com.matrix.java.chap_03;

import java.util.Scanner;

/*
    游戏：剪刀、石头、布
 */
public class Ex3_17 {
    public static void main(String[] args) {
        int randomNum = (int) (Math.random() * 3);
        String computer = getString(randomNum);
        System.out.println(randomNum);
        Scanner input = new Scanner(System.in);
        System.out.print("scissor (0) , rock (1), paper (2): ");
        int guessNum = input.nextInt();
        String person = getString(guessNum);
        int result = randomNum - guessNum;
        switch (result){
            case -2:
                System.out.println("The computer is " + computer + ". You are " + person + ". You loss");
                break;
            case -1:
                System.out.println("The computer is " + computer + ". You are " + person + ". You win");
                break;
            case 0:
                System.out.println("The computer is " + computer + ". You are " + person + " too. It is a draw");
                break;
            case 1:
                System.out.println("The computer is " + computer + ". You are " + person + ". You loss");
                break;
            case 2:
                System.out.println("The computer is " + computer + ". You are " + person + ". You win");
                break;
        }
    }

    private static String getString(int guessNum) {
        String string = null;
        switch (guessNum) {
            case 0:
                string = "scissor";
                break;
            case 1:
                string = "rock";
                break;
            case 2:
                string = "paper";
                break;
        }
        return string;
    }
}
